<?php 
include('includes/confirm.php');
$page_name = media;
require_once 'classes/Mysql.php';
//require_once 'includes/constants.php';
$mysql = New Mysql();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <?php include('includes/head.php'); ?>
<body>
<div id="wrapper">
    <?php include('includes/header.php'); ?>
    <?php include('includes/menu.php'); ?>
    
    <div id="page">
    	
	      <div id="content">
			<div id="browse_result">
				<form method="post" action="view_resource.php">
				<table class="sortable" id=anyid cellpadding="0" cellspacing="0">
					<tr>
						<th class="unsortable">Resource Info</th>
						<th class="unsortable">Details</th>
					</tr>
			<?php
				if($_POST && !empty($_POST['resource_id'])){
					$stmt=$mysql->run_query("SELECT type_id FROM resource WHERE id=? ", $_POST['resource_id']);
					// $stmt=$mysql->run_query()
					$stmt->bind_result($type_id);
					$stmt->fetch();
					$stmt->close();
					$text='"text"';
					$hidden='"hidden"';
					$title_name='"title"';
					$year_name='"year"';
					$length_name='"length"';
					$imdb_name='"imdb"';
					$rating_name='"rating"';
					$publisher_name='"publisher"';
					$isbn_name='"isbn"';
					$no_of_tracks_name='"no_of_tracks"';
					$company_name='"company"';
					$console_name='"console"';
					
					echo '<input type="hidden" name="type_id" value="'.$type_id.'">';
					switch($type_id){
						case 1: //movie
								$stmt=$mysql->run_query("SELECT r.title, r.year, m.length, m.imdb_link, m.rating
																					FROM resource r, movie m
																					WHERE r.id=m.id
																								AND r.id=?", $_POST['resource_id']);
								$stmt->bind_result($title, $year, $length, $imdb_link, $rating);
								$stmt->fetch();
								$stmt->close();
								print "<tr><td>Title</td>			<td><input type=$text name=$title_name value=$title /></td>		</tr>";
								print "<tr><td>Year</td>			<td><input type=$text name=$year_name value=$year /></td>		</tr>";
								print "<tr><td>Length</td>		<td><input type=$text name=$length_name value=$length /></td>	</tr>";
								print "<tr><td>IMDB Link</td>	<td><input type=$text name=$imdb_name value=$imdb_link /></td>	</tr>";
								print "<tr><td>Rating</td>		<td><input type=$text name=$rating_name value=$rating /></td>	</tr>";
								break;
						case 2: //book
								$stmt=$mysql->run_query("SELECT r.title, r.year, b.publisher, b.isbn
																					FROM resource r, book b
																					WHERE r.id=b.id
																								AND r.id=?", $_POST['resource_id']);
								$stmt->bind_result($title, $year, $publisher, $isbn);
								$stmt->fetch();
								$stmt->close();
								print "<tr><td>Title</td>			<td><input type=$text name=$title_name value=$title /></td>		</tr>";
								print "<tr><td>Year</td>			<td><input type=$text name=$year_name value=$year /></td>		</tr>";
								print "<tr><td>Publisher</td>	<td><input type=$text name=$publisher_name value=$publisher /></td>	</tr>";
								print "<tr><td>ISBN</td>			<td><input type=$text name=$isbn_name value=$isbn /></td>	</tr>";
								break;
						case 3: //album
								$stmt=$mysql->run_query("SELECT r.title, r.year, a.no_of_tracks
																					FROM resource r, album a
																					WHERE r.id=a.id
																								AND r.id=?", $_POST['resource_id']);
								$stmt->bind_result($title, $year, $no_of_tracks);
								$stmt->fetch();
								$stmt->close();
								print "<tr><td>Title</td>			<td><input type=$text name=$title_name value=$title /></td>		</tr>";
								print "<tr><td>Year</td>			<td><input type=$text name=$year_name value=$year /></td>		</tr>";
								print "<tr><td>No. of tracks</td>		<td><input type=$text name=$no_of_tracks_name value=$no_of_tracks /></td>	</tr>";
								break;
						case 4: // videogame
								$stmt=$mysql->run_query("SELECT r.title, r.year, v.company, v.rating, v.console
																					FROM resource r, videogame v
																					WHERE r.id=v.id
																								AND r.id=?", $_POST['resource_id']);
								$stmt->bind_result($title, $year, $company, $rating, $console);
								$stmt->fetch();
								$stmt->close();
								print "<tr><td>Title</td>			<td><input type=$text name=$title_name value=$title /></td>		</tr>";
								print "<tr><td>Year</td>			<td><input type=$text name=$year_name value=$year /></td>		</tr>";
								print "<tr><td>Company</td>		<td><input type=$text name=$company_name value=$company /></td>	</tr>";
								print "<tr><td>Rating</td>		<td><input type=$text name=$rating_name value=$rating /></td>	</tr>";
								print "<tr><td>Console</td>		<td><input type=$text name=$console_name value=$console /></td>	</tr>";
								break;
						
					}
					$show_copies=true;
				}
				
					else{
						echo "<br><br><h4>Invalid Link!!<h4>";
					}
			?>
			
			</table> <br>
			<input type="submit" name="update_user_setting" value="   Update   "><br><br>
			<?php
			echo '<input type="hidden" name="resource_id" value="'.$resource_id.'">';
			echo '<input type="hidden" name="type_id" value="'.$type_id.'">';
			?>
			</form>
			<br>
			</div>
	      </div>
	      <!-- end div#content -->
	      <div id="sidebar">
			
	      </div>
	      <!-- end div#sidebar -->
	      <div style="clear: both; height: 1px"></div>
	   
	  </div>
  
  	</div>
  	<!-- end div#page -->
    <?php include('includes/footer.php'); ?>
</div> <!-- end div#wrapper -->
</body>
</html>
